package com.ztesoft.web.baseconfig.service.impl;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ztesoft.core.common.Page;
import com.ztesoft.core.convert.IArgConversionService;
import com.ztesoft.core.idproduce.ISequenceGenerator;
import com.ztesoft.framework.exception.BaseAppException;
import com.ztesoft.framework.log.ZTEsoftLogManager;
import com.ztesoft.web.baseconfig.db.arg.DmPlanArg;
import com.ztesoft.web.baseconfig.db.dao.DmPlanDao;
import com.ztesoft.web.baseconfig.db.po.DmPlanPO;
import com.ztesoft.web.baseconfig.service.IMaintenanceService;

/**
 * <Description> <br>
 * 
 * @author lin.jie<br>
 * @version 1.0<br>
 * @taskId <br>
 * @CreateDate 2016年6月24日 <br>
 * @since V1.0<br>
 * @see com.ztesoft.web.baseconfig.service.impl <br>
 */

@Service
public class MaintenanceServiceImpl implements IMaintenanceService {

	private static final ZTEsoftLogManager logger = ZTEsoftLogManager.getLogger(MaintenanceServiceImpl.class);

	@Autowired
	private DmPlanDao dmPlanDao;

	/**
	 * 查询条件转换成Arg类的服务接口
	 */
	@Resource(name = "defaultArgConversionService")
	private IArgConversionService argConversionService;

	/**
	 * 主键生成器
	 */
	@Resource(name = "sequenceProcGenerator")
	private ISequenceGenerator sequenceGenerator;

	@Override
	public Page<DmPlanPO> queryRecordByPage(DmPlanPO record, Page<DmPlanPO> resultPage) throws BaseAppException {
		DmPlanArg arg = argConversionService.invokeArg(DmPlanArg.class, record);
		record.setPlanName(record.getPlanName().trim());
		if ("".equals(record.getPlanName())) {
			record.setPlanName(null);
		}
		if ("-1".equals(record.getExecType())) {
			record.setExecType(null);
		}
		if ("-1".equals(record.getExecFrequency())) {
			record.setExecFrequency(null);
		}
		if ("0".equals(record.getState())) {
			record.setState(null);
		}
		record.setSourceType(2);
		resultPage = dmPlanDao.selectByArgAndPageForFile(record, resultPage);
		return resultPage;
	}
}
